package com.itheima.pinda.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pinda.DTO.transportline.TransportLineDto;
import com.itheima.pinda.common.utils.PageResponse;
import com.itheima.pinda.common.utils.Result;
import com.itheima.pinda.service.PdTransportLineService;
import com.itheima.pinda.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "线路管理")
@RestController
@RequestMapping(value = "/base/line")
public class PdTransportLineController {

    @Autowired
    private PdTransportLineService transportLineService;

    @ApiOperation(value = "线路新增")
    @PostMapping(value = "/insert")
    public TransportLineDto insert(TransportLineDto transportLineDto) {

        return transportLineService.insert(transportLineDto);
    }

    @ApiOperation(value = "线路修改")
    @PostMapping(value = "/update")
    public TransportLineDto update(TransportLineDto transportLineDto) {

        return transportLineService.insert(transportLineDto);
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/Id")
    public TransportLineDto selectById(@RequestParam("id") String id) {

        return transportLineService.selectById(id);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/selectByPage")
    public PageResponse selectByPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize,
                                     @RequestParam(value = "lineNumber", required = false) String lineNumber,
                                     @RequestParam(value = "name", required = false) String name,
                                     @RequestParam(value = "transportLineTypeId", required = false) String transportLineTypeId) {

        IPage page = transportLineService.selectByPage(pageNum, pageSize, lineNumber, name, transportLineTypeId);
        return ResultUtils.pageResult(pageNum, pageSize, page);
    }

    @ApiOperation(value = "批量删除")
    @DeleteMapping(value = "/delete")
    public Result deleteById(@RequestBody List<String> ids){

        transportLineService.deleteById(ids);
        return Result.ok("删除成功！");
    }
}